package com.geezdata.cps.sdk3rd.miya.domain;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;


public class MiyaOrder {
    private String orderId;
    
    private Integer orderState;
    
    private Double orderPayment;
    
    private String orderRemark;
    
    private String payType;
    
    private Date orderTime;
    
    private Date confirmTime;
    
    private Date cancelTime;
    
    private String sheetCode;
    
    private Integer logisticId;
    
    private Double shipPrice;
    
    private Double orderCouponPrice;
    
    private Double orderSellerDiscount;
    
    private Double orderTotalPrice;
    
    private Double payPrice;
    
    private String transactionId;
    
    private Double orderPopCouponPrice;
    
    private Date modifyTime;
    
    private Integer needInvoice;
    
    private String dstProvince;
    
    private String dstCity;
    
    private String dstArea;
    
    private String dstStreet;
    
    private String dstAddress;
    
    private String dstName;
    
    private String dstMobile;
    
    private String dstTel;
    
    private List<MiyaOrderGoods> orderGoodses;

    
    public String getOrderId() {
        return orderId;
    }

    public void setOrderId(String orderId) {
        this.orderId = orderId;
    }

    public Integer getOrderState() {
        return orderState;
    }

    public void setOrderState(Integer orderState) {
        this.orderState = orderState;
    }

    public Double getOrderPayment() {
        return orderPayment;
    }

    public void setOrderPayment(Double orderPayment) {
        this.orderPayment = orderPayment;
    }

    public String getOrderRemark() {
        return orderRemark;
    }

    public void setOrderRemark(String orderRemark) {
        this.orderRemark = orderRemark;
    }

    public String getPayType() {
        return payType;
    }

    public void setPayType(String payType) {
        this.payType = payType;
    }

    public Date getOrderTime() {
        return orderTime;
    }

    public void setOrderTime(Date orderTime) {
        this.orderTime = orderTime;
    }

    public Date getConfirmTime() {
        return confirmTime;
    }

    public void setConfirmTime(Date confirmTime) {
        this.confirmTime = confirmTime;
    }

    public Date getCancelTime() {
        return cancelTime;
    }

    public void setCancelTime(Date cancelTime) {
        this.cancelTime = cancelTime;
    }

    public String getSheetCode() {
        return sheetCode;
    }

    public void setSheetCode(String sheetCode) {
        this.sheetCode = sheetCode;
    }

    public Integer getLogisticId() {
        return logisticId;
    }

    public void setLogisticId(Integer logisticId) {
        this.logisticId = logisticId;
    }

    public Double getShipPrice() {
        return shipPrice;
    }

    public void setShipPrice(Double shipPrice) {
        this.shipPrice = shipPrice;
    }

    public Double getOrderCouponPrice() {
        return orderCouponPrice;
    }

    public void setOrderCouponPrice(Double orderCouponPrice) {
        this.orderCouponPrice = orderCouponPrice;
    }

    public Double getOrderSellerDiscount() {
        return orderSellerDiscount;
    }

    public void setOrderSellerDiscount(Double orderSellerDiscount) {
        this.orderSellerDiscount = orderSellerDiscount;
    }

    public Double getOrderTotalPrice() {
        return orderTotalPrice;
    }

    public void setOrderTotalPrice(Double orderTotalPrice) {
        this.orderTotalPrice = orderTotalPrice;
    }

    public Double getPayPrice() {
        return payPrice;
    }

    public void setPayPrice(Double payPrice) {
        this.payPrice = payPrice;
    }

    public String getTransactionId() {
        return transactionId;
    }

    public void setTransactionId(String transactionId) {
        this.transactionId = transactionId;
    }

    public Double getOrderPopCouponPrice() {
        return orderPopCouponPrice;
    }

    public void setOrderPopCouponPrice(Double orderPopCouponPrice) {
        this.orderPopCouponPrice = orderPopCouponPrice;
    }

    

    public Date getModifyTime() {
        return modifyTime;
    }

    public void setModifyTime(Date modifyTime) {
        this.modifyTime = modifyTime;
    }

    public Integer getNeedInvoice() {
        return needInvoice;
    }

    public void setNeedInvoice(Integer needInvoice) {
        this.needInvoice = needInvoice;
    }

    public String getDstProvince() {
        return dstProvince;
    }

    public void setDstProvince(String dstProvince) {
        this.dstProvince = dstProvince;
    }

    public String getDstCity() {
        return dstCity;
    }

    public void setDstCity(String dstCity) {
        this.dstCity = dstCity;
    }

    public String getDstArea() {
        return dstArea;
    }

    public void setDstArea(String dstArea) {
        this.dstArea = dstArea;
    }

    public String getDstStreet() {
        return dstStreet;
    }

    public void setDstStreet(String dstStreet) {
        this.dstStreet = dstStreet;
    }

    public String getDstAddress() {
        return dstAddress;
    }

    public void setDstAddress(String dstAddress) {
        this.dstAddress = dstAddress;
    }

    public String getDstName() {
        return dstName;
    }

    public void setDstName(String dstName) {
        this.dstName = dstName;
    }

    public String getDstMobile() {
        return dstMobile;
    }

    public void setDstMobile(String dstMobile) {
        this.dstMobile = dstMobile;
    }

    public String getDstTel() {
        return dstTel;
    }

    public void setDstTel(String dstTel) {
        this.dstTel = dstTel;
    }

    public List<MiyaOrderGoods> getOrderGoodses() {
        return orderGoodses;
    }

    public void setOrderGoodses(List<MiyaOrderGoods> orderGoodses) {
        this.orderGoodses = orderGoodses;
    }

    /**
     * 
     * @param orderJson 一个具体的order response
     * @return miya order 的封装实体类
     */
    public static MiyaOrder convert(JSONObject orderJson) {
        
        MiyaOrder miyaResponseOrder = new MiyaOrder();
        
        miyaResponseOrder.setOrderId(orderJson.getString("order_id"));
        miyaResponseOrder.setOrderState(orderJson.getInteger("order_state"));
        miyaResponseOrder.setOrderPayment(orderJson.getDouble("order_payment"));
        miyaResponseOrder.setOrderRemark(orderJson.getString("order_remark"));
        miyaResponseOrder.setPayType(orderJson.getString("pay_type"));
        miyaResponseOrder.setOrderTime(orderJson.getDate("order_time"));
        miyaResponseOrder.setConfirmTime(orderJson.getDate("confirm_time"));
        miyaResponseOrder.setCancelTime(orderJson.getDate("cancel_time"));
        miyaResponseOrder.setSheetCode(orderJson.getString("sheet_code"));
        miyaResponseOrder.setLogisticId(orderJson.getInteger("logistic_id"));
        miyaResponseOrder.setShipPrice(orderJson.getDouble("ship_price"));
        miyaResponseOrder.setOrderCouponPrice(orderJson.getDouble("order_coupon_price"));
        miyaResponseOrder.setOrderSellerDiscount(orderJson.getDouble("order_seller_discount"));
        miyaResponseOrder.setOrderTotalPrice(orderJson.getDouble("order_total_price"));
        miyaResponseOrder.setPayPrice(orderJson.getDouble("pay_price"));
        miyaResponseOrder.setTransactionId(orderJson.getString("transaction_id"));
        miyaResponseOrder.setOrderPopCouponPrice(orderJson.getDouble("order_pop_coupon_price"));
        miyaResponseOrder.setModifyTime(orderJson.getDate("modify_time"));
        miyaResponseOrder.setNeedInvoice(orderJson.getInteger("need_invoice"));
        
        JSONObject dstJsonObject = orderJson.getJSONObject("address_info");
        
        miyaResponseOrder.setDstProvince(dstJsonObject.getString("dst_province"));
        miyaResponseOrder.setDstCity(dstJsonObject.getString("dst_city"));
        miyaResponseOrder.setDstArea(dstJsonObject.getString("dst_area"));
        miyaResponseOrder.setDstStreet(dstJsonObject.getString("dst_street"));
        miyaResponseOrder.setDstAddress(dstJsonObject.getString("dst_address"));
        miyaResponseOrder.setDstMobile(dstJsonObject.getString("dst_mobile"));
        miyaResponseOrder.setDstTel(dstJsonObject.getString("dst_tel"));
        miyaResponseOrder.setDstName(dstJsonObject.getString("dst_name"));
        
        JSONArray orderGoodsJsons = orderJson.getJSONArray("item_info_list");
        
        miyaResponseOrder.setOrderGoodses(convertOrderGoods(orderGoodsJsons));
        
        return miyaResponseOrder;
    }

    public static List<MiyaOrderGoods> convertOrderGoods(JSONArray orderGoodsJsons){
        
        List<MiyaOrderGoods> miyaResponseOrderGoodsList = new ArrayList<MiyaOrderGoods>();
        
        for (int i = 0; i < orderGoodsJsons.size(); i++) {
            
            JSONObject orderGoodsJson = orderGoodsJsons.getJSONObject(i);
            
            MiyaOrderGoods miyaOrderGoods = new MiyaOrderGoods();
            
            miyaOrderGoods.setItemId(orderGoodsJson.getString("item_id"));
            miyaOrderGoods.setSkuId(orderGoodsJson.getString("sku_id"));
            miyaOrderGoods.setItemName(orderGoodsJson.getString("item_name"));
            miyaOrderGoods.setItemCode(orderGoodsJson.getString("item_code"));
            miyaOrderGoods.setBarcode(orderGoodsJson.getString("barcode"));
            miyaOrderGoods.setSkuItemSize(orderGoodsJson.getString("sku_item_size"));
            miyaOrderGoods.setItemTotal(orderGoodsJson.getInteger("item_total"));
            miyaOrderGoods.setItemStat(orderGoodsJson.getInteger("item_stat"));
            miyaOrderGoods.setSalePrice(orderGoodsJson.getDouble("sale_price"));
            miyaOrderGoods.setShipPrice(orderGoodsJson.getDouble("ship_price"));
            miyaOrderGoods.setPayPrice(orderGoodsJson.getDouble("pay_price"));
            miyaOrderGoods.setCouponPrice(orderGoodsJson.getDouble("coupon_price"));
            miyaOrderGoods.setSellerDiscount(orderGoodsJson.getDouble("seller_discount"));
            miyaOrderGoods.setDealPrice(orderGoodsJson.getDouble("deal_price"));
            miyaOrderGoods.setPopCouponPrice(orderGoodsJson.getDouble("pop_coupon_price"));
            
            miyaResponseOrderGoodsList.add(miyaOrderGoods);
            
        }
        return miyaResponseOrderGoodsList;
    }
}
